package com.ruoyi.cmelasercladding.controller;

import com.ruoyi.cmelasercladding.domain.ZsCladdingUrl;
import com.ruoyi.cmelasercladding.service.IZsCladdingUrlService;
import com.ruoyi.cmenonmetal.domain.ZsOrderUrl;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * cmelasercladdingController
 * 
 * @author zousong
 * @date 2022-03-10
 */
@RestController
@RequestMapping("/url/cmelasercladding")
public class ZsCladdingUrlController extends BaseController
{
    @Autowired
    private IZsCladdingUrlService zsCladdingUrlService;

    /**
     * 查询cmelasercladding列表
     */
    @PreAuthorize("@ss.hasPermi('url:cmelasercladding:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZsCladdingUrl zsCladdingUrl)
    {
        startPage();
        List<ZsCladdingUrl> list = zsCladdingUrlService.selectZsCladdingUrlList(zsCladdingUrl);
        return getDataTable(list);
    }

    /**
     * 导出cmelasercladding列表
     */
    @PreAuthorize("@ss.hasPermi('url:cmelasercladding:export')")
    @Log(title = "cmelasercladding", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZsCladdingUrl zsCladdingUrl)
    {
        List<ZsCladdingUrl> list = zsCladdingUrlService.selectZsCladdingUrlList(zsCladdingUrl);
        ExcelUtil<ZsCladdingUrl> util = new ExcelUtil<ZsCladdingUrl>(ZsCladdingUrl.class);
        util.exportExcel(response, list, "cmelasercladding数据");
    }

    /**
     * 获取cmelasercladding详细信息
     */
    @PreAuthorize("@ss.hasPermi('url:cmelasercladding:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zsCladdingUrlService.selectZsCladdingUrlById(id));
    }

    /**
     * 新增cmelasercladding
     */
    @PreAuthorize("@ss.hasPermi('url:cmelasercladding:add')")
    @Log(title = "cmelasercladding", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZsCladdingUrl zsCladdingUrl)
    {
        return toAjax(zsCladdingUrlService.insertZsCladdingUrl(zsCladdingUrl));
    }

    /**
     * 修改cmelasercladding
     */
    @PreAuthorize("@ss.hasPermi('url:cmelasercladding:edit')")
    @Log(title = "cmelasercladding", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZsCladdingUrl zsCladdingUrl)
    {
        return toAjax(zsCladdingUrlService.updateZsCladdingUrl(zsCladdingUrl));
    }

    /**
     * 删除cmelasercladding
     */
    @PreAuthorize("@ss.hasPermi('url:cmelasercladding:remove')")
    @Log(title = "cmelasercladding", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zsCladdingUrlService.deleteZsCladdingUrlByIds(ids));
    }

    //获取下载文件信息
    @GetMapping("/getFileInformation")
    public AjaxResult getFileInformation(ZsCladdingUrl zsCladdingUrl){
        AjaxResult ajaxResult = new AjaxResult();
        List<ZsCladdingUrl> list = zsCladdingUrlService.selectZsCladdingUrlList(zsCladdingUrl);
        if(list.size() != 0){
            ZsCladdingUrl zsCladdingUrl1 = list.get(0);
            if(StringUtils.isNotEmpty(zsCladdingUrl1.getCladdingUpload())){
                String orderfilename = "." +  StringUtils.substringAfterLast(zsCladdingUrl1.getCladdingUpload(), ".");
                System.out.println("-------------------"+orderfilename);
                ajaxResult.put("orderfilename",orderfilename);
                ajaxResult.put("orderurl",zsCladdingUrl1.getCladdingUpload());
            }

            if(StringUtils.isNotEmpty(zsCladdingUrl1.getCladdingUpload())){
                String predatafilename ="." +  StringUtils.substringAfterLast(zsCladdingUrl1.getCladdingUpload(), ".");
                ajaxResult.put("predatafilename",predatafilename);
                ajaxResult.put("predataurl",zsCladdingUrl1.getCladdingUpload());
            }
        }

        return ajaxResult;

    }



}
